//
//  NSString+Tools.m
//  demo10-9
//
//  Created by xx on 15/10/11.
//  Copyright (c) 2015年 xx. All rights reserved.
//

#import "NSString+Tools.h"
#import "CommonCrypto/CommonDigest.h"
#import "NSString+font.h"
@implementation NSString (Tools)

/**扩展方法 所有string类型都可以调用 文字计算宽度 高度*/
-(CGSize)sizeWithFont:(UIFont *)font maxSize:(CGSize)maxSize
{
    
    NSDictionary *attrs = @{NSFontAttributeName : font};
    return [self boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
    
}

#pragma 计算字体的宽
+(CGFloat)calculateLabelWidth:(NSString *)title font:(UIFont *)font AndHeight:(CGFloat)height
{
    float width = [title boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, height) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil].size.width;
    return width;
}
#pragma mark - 计算字体高
+(CGFloat)calculateLabelHeight:(NSString *)title font:(UIFont *)font AndWidth:(CGFloat)width
{
    NSString *newTitle = [NSString stringWithFormat:@"%@0",title];
    float height = [newTitle boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil].size.height;
    return height;
}





+ (NSString *)changeQuantityUnit:(id)count
{
    NSString *newStr = nil;
    if ([count intValue] > 9999) {
        
        float newCount = [count floatValue] / 10000.0;
        
        newStr = [NSString stringWithFormat:@"%.2f万",newCount];
    }
    else{
        if ([NSString isBlankString:count]) {
            
            newStr = @"0";
        }
        else{
            newStr = [NSString stringWithFormat:@"%@",count];
        }
    }
    return newStr;
}




@end
